import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["page"];

/**
 * model 平台语言
 * @date: 2018-6-22


 */
import { getResponse, createPagination, parseParameters } from 'utils/utils';
import { fetchPromptList as _fetchPromptList, createPrompt as _createPrompt, deletePrompt as _deletePrompt, fetchPromptDetail as _fetchPromptDetail, updatePrompt as _updatePrompt, refresh as _refresh } from "../services/promptService";
import { queryLanguage } from "../services/languagesService";
export default {
  namespace: 'prompt',
  state: {
    promptList: [],
    // 多语言列表
    languageList: [],
    // 语言列表
    promptDetail: {},
    // 多语言详情
    pagination: {} // 分页对象

  },
  effects: {
    // 获取初始化数据
    // *init(_, { call, put }) {
    //   const res = yield call(queryUnifyIdpValue, 'CPFM.LANGUAGE');
    //   const list = getResponse(res);
    //   if (list) {
    //     yield put({
    //       type: 'updateState',
    //       payload: {
    //         languageList: list,
    //       },
    //     });
    //   }
    // },
    // 查询初始化语言数据
    fetchLanguages: /*#__PURE__*/_regeneratorRuntime.mark(function fetchLanguages(_ref, _ref2) {
      var payload, call, put, page, query, response, languageData;
      return _regeneratorRuntime.wrap(function fetchLanguages$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              page = payload.page, query = _objectWithoutProperties(payload, _excluded);
              _context.next = 5;
              return call(queryLanguage, payload);

            case 5:
              response = _context.sent;
              languageData = getResponse(response);

              if (!languageData) {
                _context.next = 10;
                break;
              }

              _context.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  query: query,
                  languageList: languageData.content
                }
              });

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, fetchLanguages);
    }),
    // 获取平台语言列表
    fetchPromptList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchPromptList(_ref3, _ref4) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchPromptList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _context2.next = 4;
              return call(_fetchPromptList, parseParameters(payload));

            case 4:
              res = _context2.sent;
              list = getResponse(res);

              if (!list) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  promptList: list.content,
                  pagination: createPagination(list)
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchPromptList);
    }),
    // 获取平台语言详情
    fetchPromptDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchPromptDetail(_ref5, _ref6) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchPromptDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call, put = _ref6.put;
              _context3.next = 4;
              return call(_fetchPromptDetail, parseParameters(payload));

            case 4:
              res = _context3.sent;
              list = getResponse(res);

              if (!list) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  promptDetail: list
                }
              });

            case 9:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchPromptDetail);
    }),
    // 新增平台语言
    createPrompt: /*#__PURE__*/_regeneratorRuntime.mark(function createPrompt(_ref7, _ref8) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createPrompt$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_createPrompt, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, createPrompt);
    }),
    // 刷新多语言缓存
    refresh: /*#__PURE__*/_regeneratorRuntime.mark(function refresh(_ref9, _ref10) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function refresh$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call;
              _context5.next = 4;
              return call(_refresh, payload);

            case 4:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, refresh);
    }),
    // 更新平台语言
    updatePrompt: /*#__PURE__*/_regeneratorRuntime.mark(function updatePrompt(_ref11, _ref12) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updatePrompt$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call;
              _context6.next = 4;
              return call(_updatePrompt, payload);

            case 4:
              res = _context6.sent;
              return _context6.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, updatePrompt);
    }),
    // 删除平台语言
    deletePrompt: /*#__PURE__*/_regeneratorRuntime.mark(function deletePrompt(_ref13, _ref14) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deletePrompt$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call;
              _context7.next = 4;
              return call(_deletePrompt, payload);

            case 4:
              res = _context7.sent;
              return _context7.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, deletePrompt);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref15) {
      var payload = _ref15.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};